using GameFramework.Event;
using System;

namespace TowerDefence_Zombie
{
    public class GuideCondition_PlaceTower : GuideCondition_Base
    {
        public GuideCondition_PlaceTower(DRGuideCondition conditionInfo, Action conitionCompleteClick)
            : base(conditionInfo, conitionCompleteClick)
        {

        }

        public override void StartCondition()
        {
            base.StartCondition();
            GameEntry.Event.Subscribe(ChangePlacementAreaEventArgs.EventId, OnPlaceTower);
        }

        private void OnPlaceTower(object sender, GameEventArgs e)
        {
            ChangePlacementAreaEventArgs ne = (ChangePlacementAreaEventArgs)e;
            if (ne == null)
                return;

            if (ne.TowerId > 0)
            {
                IsCompleteFlag = true;
            }
        }

        public override void Dispose()
        {
            GameEntry.Event.Unsubscribe(ChangePlacementAreaEventArgs.EventId, OnPlaceTower);
            base.Dispose();
        }
    }
}
